<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

<%
    request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/argeeCommon.jsp" %>
<%@ include file="/WEB-INF/JSP/backHome/modalWindows/againstAuditCommon.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/backLayout.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/CSS/bombBox.css">
    <script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="<%=path%>/HoganJS/handlebars-v4.0.11.js"></script>
    <%@ include file="/WEB-INF/JSP/ajax.jsp" %>
</head>
<style>
    select{width: 170px;height: 31px}
    .gn_name{padding-top: 5px}

    .div_zilei {
        width: 94.5%;
        height: 30px
    }
    .tr{height:40px;background: #a9bbe0}
    .tr td{font-size: 14px;color: #ffffff}
    .tr_td{height: 40px;}
    .tr_td td{border-bottom: 1px solid #ededed;text-align: center;}
    tr td:nth-child(1) {font-size: 14px;color: #cccccc}
    .date{border: 0;background: #ffffff;text-align: center;}
    .tr_td td:nth-child(1){border-left: 1px solid #cccccc;}
    .tr_td td:nth-child(3){border-right: 1px solid #cccccc;}
    .addTable.deleteTable:HOVER{cursor:pointer;}
    type[type='checkbox']{width: 15px}
    #table1 input{width: 170px}
    #table3 input{width: 170px;}
    .fseq2{width:25px;border:none;color:#cccccc;text-align: center;}
    .div_input_hang select{width: 234px}
    .div_input_hang {
        width: 100%;
        height: 40px;
    }
    .input_hang {
        float: left;
        width: 500px;
        height: 40px;
    }
</style>
<body style="background: #f5f5f5">
<div class="main">
    <div id="modal-overlay">

    </div>
    <div class="modal-data1">
        <div style="height: 60px">
            <ul>
                <li  style="text-align: left;margin-left: 60px;height: 40px;line-height: 40px">
                    <span>名称：</span>
                    <span>
                                <input class="name" type="text" >
                           </span>
                    <span>类型：</span>
                    <span>
                                <input class="type" type="text" >
                           </span>
                    <span>
                               <button class="findBtn1">
                                   查询
                               </button>
                           </span>
                </li>
            </ul>
        </div>
        <div style="width:1100px; height:350px; overflow:scroll;">
            <form action="">
                <table class="head1" style="width: auto;white-space:nowrap;border-spacing: 0px">
                    <tr style="background: #f2f2f2;height: 30px;line-height: 20px;" class="sel">
                        <td style="width: 20px"></td>
                        <td>物品名称</td>
                        <td>物品编号</td>
                        <td>物品类型</td>
                        <td>规格编号</td>
                        <td>物品单价</td>
                        <td>创建人</td>
                        <td>创建时间</td>
                        <td>最后修改人</td>
                        <td>最后修改时间</td>
                        <td>驾校id</td>
                    </tr>
                    <c:forEach items="${goodstables}" var="goodstables">
                        <tr style="margin-top: 45px" class="xysj">
                            <td style="width: 20px;"><input type="checkbox" class="check" value="${goodstables.wpId}" name="train" style="width: 15px;"/></td>
                            <td>${goodstables.wpName}</td>
                            <td>${goodstables.wpId}</td>
                            <td>${goodstables.wpType}</td>
                            <td>${goodstables.wpGgid}</td>
                            <td>${goodstables.wpPrice}</td>
                            <td>${goodstables.wpCreator}</td>
                            <td>${goodstables.wpCreationtime}</td>
                            <td>${goodstables.wpLastmodifier}</td>
                            <td>${goodstables.wpLastmodificationtime}</td>
                            <td>${goodstables.wpSchoolid}</td>
                        </tr>
                    </c:forEach>
                </table>
            </form>
        </div>
        <button class="subtn1" style="width: 150px;position: absolute;bottom: 25px;font-size: 16px;left: 280px">
            确定
        </button>
        <button class="btn" style="width: 150px;position: absolute;bottom: 25px;font-size: 16px;right: 280px">
            关闭
        </button>
    </div>
    <c:if test="${empty inwareHouse}">
        <div class="weizhi">
            库存管理>>物品入库>>新增
        </div>
    </c:if>
    <c:if test="${not empty inwareHouse}">
        <c:if test="${inwareHouse.cfbillstate <= 3}">
            <div class="weizhi">
                库存管理>>物品入库>>修改
            </div>
        </c:if>
    </c:if>
    <c:if test="${not empty inwareHouse}">
        <c:if test="${inwareHouse.cfbillstate > 3}">
            <div class="weizhi">
                库存管理>>物品入库>>查看
            </div>
        </c:if>
    </c:if>
    <div class="div_body" style="box-shadow: 0 0 5px #cccccc;height: 950px">
        <div class="div_form">
            <!----------------------------- 新增 --------------------------------->
            <c:if test="${empty inwareHouse}">
                <form action="<%=path%>/DrivingSys/addInwareHouse" class="form" method="post"
                      onsubmit="return verify();">
                    <div class="div_input_hang">
                        <div class="input_hang">
                            <span class="gn_name">驾校&nbsp;:&nbsp;</span>
                            <input  type="text" name="name"  value="${department.fnameL2}" readonly style="color: gray;"/>
                        </div>
                        <div class="input_hang">
                            <span class="gn_name">单据编号&nbsp;:&nbsp;</span>
                            <input  type="text" name="fnumber" value="${fnumber}" style="color: gray;" readonly/>
                        </div>
                        <div class="input_hang">
                            <span class="gn_name">业务日期&nbsp;:&nbsp;</span>
                            <input  type="text" name="fbizdate"  id="ywrq" value="${time}"
                                    onclick="WdatePicker({el:'ywrq',dateFmt:'yyyy-MM-dd'})"/>
                            <img onclick="WdatePicker({el:'ywrq',dateFmt:'yyyy-MM-dd'})"
                                 src="<%=path%>/image/date.jpg"  align="absmiddle" style="padding-left: 15px">
                        </div>
                    </div>
                    <div class="div_input_hang">
                        <div class="input_hang">
                            <span class="gn_name">备注&nbsp;:&nbsp;</span>
                            <input name="fdescription"/>
                        </div>
                        <div class="input_hang">
                            <span class="gn_name">单据状态&nbsp;:&nbsp;</span>
                            <select name="cfbillstate" disabled="disabled">
                                <option style="color: gray;">新增</option>
                            </select>
                        </div>
                    </div>

                    <div class="div_zilei">
                        <div style="width: 83%;text-align: right;">
                            <img src="<%=path%>/image/insert2323.jpg" class="addTable">
                            <span style="padding-right: 20px;color: #a9bbe0;font-size: 14px" class="addTable">添加</span>
                            <img src="<%=path%>/image/delete212.png" class="deleteTable">
                            <span class="deleteTable" style="color: #a9bbe0;font-size: 14px" class="deleteTable">删除</span>
                        </div>
                    </div>
                    <input type="hidden" class="stu">
                    <div style="min-height: 500px;width: 83%;padding-left: 90px;position: relative;">
                        <div style="overflow:scroll;height: 500px;width: 100%">
                            <table  width="100%" align="center" id="table1" style="min-height:50px;border-spacing:0;">
                                <tr class="tr">
                                    <td  width="20px"></td>
                                    <td  width="30px"></td>
                                    <td align="center">物品名称</td>
                                    <td align="center">物品规格</td>
                                    <td align="center">物品类型</td>
                                    <td align="center">物品单价</td>
                                    <td align="center">入库单价</td>
                                    <td align="center">入库数量</td>
                                    <td align="center">入库总价</td>
                                    <td align="center">入库备注</td>
                                </tr>
                            </table>
                        </div>
                    </div>


                    <div class="div_input_hang" style="margin-top: 50px">
                        <div class="input_hang">
                            <span class="gn_name">审核人&nbsp;:&nbsp;</span>
                            <input name="fhandlerid" readonly style="color: gray;" type="text"/>
                        </div>
                        <div class="input_hang">
                            <span class="gn_name">创建者&nbsp;:&nbsp;</span>
                            <input name="fcreatorid2" readonly value="${name}" style="color: gray;" type="text"/>
                            <input name="fcreatorid" readonly  style="color: gray;" type="hidden"/>
                        </div>
                        <div class="input_hang">
                            <span class="gn_name">创建时间&nbsp;:&nbsp;</span>
                            <input name="fcreatetime" style="color: gray;"readonly="readonly" type="text"/>
                        </div>
                    </div>

                    <div class="div_tj" style="padding-top: 0px">
                        <div>
                            <input class="input_submit bc" value="" type="submit" style="margin-right: 30px;"、>
                        </div>
                        <div>
                            <input type="button" class="input_back fh" value="" onclick="back()"/>
                        </div>
                    </div>
                </form>
            </c:if>

            <!----------------------------- 修改 --------------------------------->
            <c:if test="${not empty inwareHouse}">
                <c:if test="${inwareHouse.cfbillstate <= 3}">
                    <form action="<%=path%>/DrivingSys/editInwareHouse" class="form" method="post"
                          onsubmit="return verify();">
                        <div class="div_input_hang">
                            <div class="input_hang">
                                <span class="gn_name">驾校&nbsp;:&nbsp;</span>
                                <input  type="text" name="name"  value="${inwareHouse.companyname}" readonly="readonly" style="color: gray;"/>
                                <input type="hidden" value="${inwareHouse.fid}" name="fid" id="fid">
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">单据编号&nbsp;:&nbsp;</span>
                                <input type="text" name="fnumber" id="fnumber" value="${inwareHouse.fnumber}"
                                       style="color: gray;" readonly="readonly"/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">业务日期&nbsp;:&nbsp;</span>
                                <input  type="text" name="fbizdate"  id="ywrq" value="${inwareHouse.fbizdate}"
                                        onclick="WdatePicker({el:'ywrq',dateFmt:'yyyy-MM-dd'})"/>
                                <img onclick="WdatePicker({el:'ywrq',dateFmt:'yyyy-MM-dd'})"
                                     src="<%=path%>/image/date.jpg"  align="absmiddle" style="padding-left: 15px">
                            </div>
                        </div>
                        <div class="div_input_hang">
                            <div class="input_hang">
                                <span class="gn_name">备注&nbsp;:&nbsp;</span>
                                <input name="fdescription" value="${inwareHouse.fdescription}"/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">单据状态&nbsp;:&nbsp;</span>
                                <select name="cfbillstate" disabled="disabled">
                                    <option style="color: gray;">保存</option>
                                </select>
                            </div>
                        </div>

                        <div class="div_zilei">
                            <div style="width: 83%;text-align: right;">
                                <img src="<%=path%>/image/insert2323.jpg" class="addTable">
                                <span style="padding-right: 20px;color: #a9bbe0;font-size: 14px" class="addTable">添加</span>
                                <img src="<%=path%>/image/delete212.png" class="deleteTable">
                                <span class="deleteTable" style="color: #a9bbe0;font-size: 14px" class="deleteTable">删除</span>
                            </div>
                        </div>
                        <input type="hidden" class="stu">
                        <input type="hidden" id="auditState" value="${AuditState}">
                        <div style="min-height: 500px;width: 83%;padding-left: 90px;position: relative;">
                            <div style="overflow:scroll;height: 500px;width: 100%">
                                <table  width="100%" align="center" id="table1" style="min-height:50px;border-spacing:0;">
                                    <tr class="tr">
                                        <td  width="20px"></td>
                                        <td  width="30px"></td>
                                        <td align="center">物品名称</td>
                                        <td align="center">物品规格</td>
                                        <td align="center">物品类型</td>
                                        <td align="center">物品单价</td>
                                        <td align="center">入库单价</td>
                                        <td align="center">入库数量</td>
                                        <td align="center">入库总价</td>
                                        <td align="center">入库备注</td>
                                    </tr>
                                    <c:forEach items="${inwareHouseEntries}" var="s">
                                        <tr style="margin-top: 45px" class="jx${s.fseq}">
                                            <td width="20px"><input type="checkbox" name="check" style="width: 15px"></td>

                                            <td>

                                                <input type="text" readonly="readonly" class="fseq2" value="${s.fseq}" style="width: 40px">
                                                <input type="hidden" name="fseq" class="fseq" value="${s.fseq}">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGoodsname" class="rkGoodsname is_click_ne"
                                                       onclick="cl($(this))" value="${s.rkGoodsname}"  readonly unselectable="on">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGgid" class="rkGgid" readonly unselectable="on" value="${s.rkGgid}">
                                                <input type="hidden" name="wpId" value="${s.rkGoodsid}">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGoodstype" class="rkGoodstype" readonly unselectable="on" value="${s.rkGoodstype}">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGoodsprice" class="rkGoodsprice" readonly unselectable="on"  value="${s.rkGoodsprice}" onblur="cfamount2($(this))">
                                            </td>

                                            <td>
                                                <input type="text"  name="rkInwarehouseprice" class="rkInwarehouseprice"  value="${s.rkInwarehouseprice}" onblur="cfamount3(this)">
                                            </td>

                                            <td>
                                                <input type="text"  name="rkInwarehousequantity" class="rkInwarehousequantity" value="${s.rkInwarehousequantity}" onblur="cfamount3(this)">
                                            </td>

                                            <td>
                                                <input type="text" name="rkInwarehousetotalprices" class="rkInwarehousetotalprices" readonly unselectable="on" value="${s.rkInwarehousetotalprices}">
                                            </td>

                                            <td>
                                                <input type="text"  name="rkInwarehouseuse" class="rkInwarehouseuse" value="${s.rkInwarehouseuse}" />
                                            </td>

                                        </tr>
                                    </c:forEach>
                                </table>
                            </div>
                        </div>

                        <div class="div_input_hang" style="margin-top: 50px">
                            <div class="input_hang">
                                <span class="gn_name">审核人&nbsp;:&nbsp;</span>
                                <input name="fhandlerid" readonly="readonly" style="color: gray;" type="text" value="${inwareHouse.auditname}"/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">创建者&nbsp;:&nbsp;</span>
                                <input name="fcreatorid2" readonly="readonly" value="${inwareHouse.createname}" style="color: gray;" type="text"/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">创建时间&nbsp;:&nbsp;</span>
                                <input name="fcreatetime" style="color: gray;"readonly="readonly" type="text" value="${inwareHouse.fcreatetime}"/>
                            </div>
                        </div>

                        <div class="div_tj" style="padding-top: 0px">
                            <shiro:hasPermission name="/editInwareHouse">
                                <div>
                                    <input class="input_submit bc" value="" type="submit" >
                                </div>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="/submitInwareHouse">
                                <div style="padding-right: 50px">
                                    <input type="button" class="input_submit tj" value="" id="submit">
                                </div>
                            </shiro:hasPermission>
                            <input type="hidden" id="auditState" value="${AuditState}">
                            <div>
                                <input type="button" class="input_back fh" value="" onclick="back()"/>
                            </div>
                        </div>
                    </form>
                </c:if>
            </c:if>
            <!----------------------------- 查看 --------------------------------->
            <c:if test="${not empty inwareHouse}">
                <c:if test="${inwareHouse.cfbillstate > 3 }">
                    <form action="<%=path%>/DrivingSys/auditInwarehouse" class="form">
                        <div class="div_input_hang">
                            <div class="input_hang">
                                <span class="gn_name">驾校&nbsp;:&nbsp;</span>
                                <input  type="text" name="name"  value="${inwareHouse.companyname}" readonly style="color: gray;"/>
                                <input type="hidden" value="${inwareHouse.fid}" name="fid" id="fid">
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">单据编号&nbsp;:&nbsp;</span>
                                <input type="text" name="fnumber" id="fnumber" value="${inwareHouse.fnumber}"
                                       style="color: gray;" readonly/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">业务日期&nbsp;:&nbsp;</span>
                                <input  type="text" name="fbizdate"  id="ywrq" value="${inwareHouse.fbizdate}" readonly/>
                                <img  src="<%=path%>/image/date.jpg" style="padding-left: 15px">
                            </div>
                        </div>
                        <div class="div_input_hang">
                            <div class="input_hang">
                                <span class="gn_name">备注&nbsp;:&nbsp;</span>
                                <input name="fdescription" value="${inwareHouse.fdescription}" readonly/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">单据状态&nbsp;:&nbsp;</span>
                                <select name="cfbillstate" disabled="disabled">
                                    <c:if test="${inwareHouse.cfbillstate == 4}">
                                        <option style="color: gray;">提交</option>
                                    </c:if>
                                    <c:if test="${inwareHouse.cfbillstate == 5}">
                                        <option style="color: gray;">审核</option>
                                    </c:if>
                                </select>
                            </div>
                        </div>

                        <div class="div_zilei">
                            <div style="width: 93%;text-align: right;">
                                    <%--<img src="<%=path%>/image/insert2323.jpg">
                                    <span style="padding-right: 20px;color: #a9bbe0;font-size: 14px">添加</span>
                                    <img src="<%=path%>/image/delete212.png">
                                    <span style="color: #a9bbe0;font-size: 14px">删除</span>--%>
                            </div>
                        </div>
                        <input type="hidden" id="state" value="${inwareHouse.cfbillstate}">
                        <input type="hidden" class="stu">
                        <input type="hidden" id="type">
                        <div style="min-height: 500px;width: 88%;padding-left: 90px;position: relative;">
                            <div style="overflow:scroll;height: 500px;width: 100%">
                                <table  width="100%" align="center" id="table3" style="min-height:50px;border-spacing:0;">
                                    <tr class="tr">
                                        <td  width="20px"></td>
                                        <td  width="30px"></td>
                                        <td align="center">物品名称</td>
                                        <td align="center">物品规格</td>
                                        <td align="center">物品类型</td>
                                        <td align="center">物品单价</td>
                                        <td align="center">入库单价</td>
                                        <td align="center">入库数量</td>
                                        <td align="center">入库总价</td>
                                        <td align="center">入库备注</td>
                                    </tr>
                                    <c:forEach items="${inwareHouseEntries}" var="s">
                                        <tr style="margin-top: 45px" class="jx${s.fseq}">
                                            <td width="20px"><input type="checkbox" name="check" style="width: 15px"></td>

                                            <td>

                                                <input type="text" readonly="readonly" class="fseq2" value="${s.fseq}" style="width: 40px">
                                                <input type="hidden" name="fseq" class="fseq" value="${s.fseq}">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGoodsname" class="rkGoodsname is_click_ne"
                                                       value="${s.rkGoodsname}"  readonly unselectable="on">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGgid" class="rkGgid" readonly unselectable="on" value="${s.rkGgid}">
                                                <input type="hidden" name="wpId" value="${s.rkGoodsid}">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGoodstype" class="rkGoodstype" readonly unselectable="on" value="${s.rkGoodstype}">
                                            </td>

                                            <td>
                                                <input type="text" name="rkGoodsprice" class="rkGoodsprice" readonly unselectable="on"  value="${s.rkGoodsprice}" onblur="cfamount2($(this))">
                                            </td>

                                            <td>
                                                <input type="text" id="rkInwarehouseprice" name="rkInwarehouseprice" class="rkInwarehouseprice"   readonly unselectable="on" value="${s.rkInwarehouseprice}">
                                            </td>

                                            <td>
                                                <input type="text" id="rkInwarehousequantity" name="rkInwarehousequantity" class="rkInwarehousequantity"  readonly unselectable="on" value="${s.rkInwarehousequantity}">
                                            </td>

                                            <td>
                                                <input type="text" id="rkInwarehousetotalprices" name="rkInwarehousetotalprices" class="rkInwarehousetotalprices" readonly unselectable="on" value="${s.rkInwarehousetotalprices}" onblur="cfamount3($(this))">
                                            </td>

                                            <td>
                                                <input type="text" id="rkInwarehouseuse" name="rkInwarehouseuse" class="rkInwarehouseuse" value="${s.rkInwarehouseuse}" readonly unselectable="on" >
                                            </td>

                                        </tr>
                                    </c:forEach>
                                </table>
                            </div>
                        </div>

                        <div class="div_input_hang" style="margin-top: 50px">
                            <div class="input_hang">
                                <span class="gn_name">审核人&nbsp;:&nbsp;</span>
                                <input name="fhandlerid" readonly="readonly" style="color: gray;" type="text" value="${inwareHouse.auditname}"/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">创建者&nbsp;:&nbsp;</span>
                                <input name="fcreatorid2" readonly="readonly" value="${inwareHouse.createname}" style="color: gray;" type="text"/>
                            </div>
                            <div class="input_hang">
                                <span class="gn_name">创建时间&nbsp;:&nbsp;</span>
                                <input name="fcreatetime" style="color: gray;"readonly="readonly" type="text" value="${inwareHouse.fcreatetime}"/>
                            </div>

                        </div>
                        <div class="div_tj">
                            <c:if test="${inwareHouse.cfbillstate == 4}">
                                <shiro:hasPermission name="/auditInwarehouse">
                                    <div style="padding-right: 50px">
                                        <input type="button" class="input_submit sh" value="" id="sh">
                                        <input type="hidden" value="1">
                                    </div>
                                </shiro:hasPermission>
                            </c:if>
                            <shiro:hasPermission name="/againstInwareHouse">
                                <div style="padding-right: 50px">
                                    <input type="button" class="input_submit fsh" value="" id="fsh">
                                    <input type="hidden" value="2">
                                </div>
                            </shiro:hasPermission>
                            <div>
                                <input type="button" class="input_submit cklc" value=""
                                       onclick="lookActivitiImg('${key}',$('#fnumber').val())"/>
                            </div>
                            <div>
                                <input type="button" class="input_back fh" value="" onclick="back()"/>
                            </div>
                        </div>

                    </form>
                </c:if>
            </c:if>

        </div>
    </div>
</div>
</body>

<script type="text/javascript">
    $(document).ready(function(){
        var type = "${type}"
        if(type == null || type == ''){

        }else{
            editAlert();
        }
    });
    //删除行
    $(".deleteTable").click(function(){
        var tr_len = $("#table1 tr").length;
        if(tr_len == 1){

        }else{
            var s = '';
            $('input:checkbox[name=check]').each(function(i) {
                if($(this).is(':checked')){
                    $(this).parent().parent().remove();
                    s = '1';
                }
            });
            //判断是否选中
            if(s == null || s == ''){
                alert("请选择一条数据删除");
                return false;
            }
            if($("#table1 tr").length == 2){
                $("#table2").css('display','none')
            }
            //重新排序
            $('#table1 tr td .fseq').each(function(i) {
                var s = i*1 + 1*1;
                $(this).val(s);
                $(this).prev().val(s);
                $(this).parent().parent().attr("class",'jx'+s);
                var blrq = 'blrq'+s;//办理日期
                var dqrq = 'dqrq'+s;//结束日期
                $(this).parent().parent().find(".cfbizdate").attr("id",blrq);
                $(this).parent().parent().find(".cfbizdate").attr("onclick", "WdatePicker({el:"+blrq+",dateFmt:'yyyy-MM-dd'})");
                $(this).parent().parent().find(".cfenddate").attr("id",dqrq);
                $(this).parent().parent().find(".cfenddate").attr("onclick", "WdatePicker({el:"+dqrq+",dateFmt:'yyyy-MM-dd'})")
            })
        }
    });

    //返回
    function back(){
        location = '<%=path%>/DrivingSys/queryswareHouse/look.action';
    }

    //开启学员弹框
    function cl(_this){
        var jx = _this.parent().parent().prop("class");
        $(".stu").val(jx);
        $('#modal-overlay').css('visibility','visible');
        $('.modal-data1').css('visibility','visible')
    }

    //添加一行
    $('.addTable').click(function(){
        var tr_len = $("#table1 tr").length;
        var str = "";
        str+='<tr style="margin-top: 45px" class=jx'+tr_len+'>';
        str+='<td width="20px"><input type="checkbox" name="check" style="width: 15px" ></td>';
        str+='<td><input type="text" readonly="readonly" class="fseq2" value='+tr_len+' style="width: 40px"><input type="hidden" name="fseq" class="fseq" value='+tr_len+'></td>';
        str+= '<td><input type="text" name="rkGoodsname" class="rkGoodsname is_click_ne" onclick = "cl($(this))"></td>';
        str+= '<td><input type="text" id="rkGgid" name="rkGgid" class="rkGgid" readonly unselectable="on"><input type="hidden" name="wpId"></td>'
        str+='<td><input type="text" name="rkGoodstype" class="rkGoodstype" readonly unselectable="on" </td>';
        str+='<td><input type="text"  name="rkGoodsprice" class="rkGoodsprice" readonly unselectable="on"></td>';
        str+='<td><input type="text"  name="rkInwarehouseprice" class="rkInwarehouseprice"  onblur="cfamount3(this)"></td>';
        str+='<td><input type="text"  name="rkInwarehousequantity" class="rkInwarehousequantity" onblur="cfamount3(this)"></td>';
        str+='<td><input type="text"  name="rkInwarehousetotalprices" class="rkInwarehousetotalprices" readonly   ></td>';
        str+='<td><input type="text"  name="rkInwarehouseuse" class="rkInwarehouseuse"></td>';
        $("#table1").append(str)
    });

    //金额
    function cfamount2(_this) {
        //避免最后一个字符串是.
        _this.val((_this.val().replace(/\.$/g, "")));
        if (_this.val() == '-') {
            _this.val("")
        }
        //判断输入错误
        if (isNaN(Number(_this.val()))) {
            _this.val("")
        }
    }
    function cfamount3(_this) {
        var $this = $(_this);
        var price, num, title;
        var name = $this.prop("name");
        if (name == 'rkInwarehousequantity') {
            price = $this.parent().prev().find("input").val();
            num = $this.val();
        }
        if (price != '' && num != '') {
                if(price!= null&&num != null){
                    var price1 = parseFloat(price);
                    var num1 = parseInt(num);
                    title = price1 * num1;
                    console.log(title);
                    $this.parent().next().find("input").val(title);
                }
        } else {
            $this.parent().next().find("input").val(0);
            return
        }


    }




    //比较时间
    function compareTime(_this) {
        var startTime, endTime;
        var name = _this.prop("name");
        if (name == 'cfbizdate') {
            startTime = _this.val();
            endTime = _this.parent().next().find("input").val();
        } else {
            endTime = _this.val();
            startTime = _this.parent().prev().find("input").val();
        }
        if (startTime != '' && endTime != '') {
            var day1 = new Date(startTime);
            var day2 = new Date(endTime);
            if ((day1.getTime() - day2.getTime()) > 0) {
                alert("开始时间不能大于结束时间");
                if (name == 'cfbizdate') {
                    _this.val("");
                    _this.parent().next().find("input").val("");
                } else {
                    _this.val("");
                    _this.parent().prev().find("input").val("");
                }
            }
        }
    }
    //可以输入小数点
    $(".cfamount").live('keyup', function(event) {
        //最后一位是小数点的话，移除
        var $amountInput = $(this);
        //响应鼠标事件，允许左右方向键移动
        event = window.event || event;
        if(event.keyCode == 37 | event.keyCode == 39) {
            return;
        }
        //获取父类class名称
        var superclass = $(this).parent().parent().prop("class");
        var clazz = $(this).prop("class");
        //获取输入框的值
        var value = $('.'+clazz+'').val();
        //判断负数是否在第一位
        if(value.substring(0,1) == '-'){

        }
        //判断负数不是在第一位，替换
        if(value.lastIndexOf('-') > 0){
            $('.superclass .' + clazz + '').val("")
            // $amountInput.val($amountInput.val().replace('-','')
        }
        //先把非数字的都替换掉，除了数字和.
        $amountInput.val($amountInput.val().replace(/[^\-?\d.]/g, "").
        //只允许一个小数点
        replace(/^\./g, "").replace(/\.{2,}/g, ".").
        //只能输入小数点后两位
        replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'));
    });

    /* 关闭弹出框    */
    $('.btn').click(function(){
        $('#modal-overlay').css('visibility','hidden');
        $('.modal-data1').css('visibility','hidden')
    });

    //根据名称查询物品
    $('.findBtn1').click(function(){
        var name=$('.name').val();
        var type = $(".type").val();
        $.ajax({
            url:'<%=path%>/DrivingSys/queryRKGoodsByInfo',
            type: "post",
            data:{'name':name,'type':type},
            dataType:"json",
            success: function(json) {
                var str='';
                for(var i=0;i<json.length;i++) {
                    str+='<tr style="margin-top: 45px;height: 30px;" class="xysj"><td><input style="width: 15px;height: 15px" ';
                    str+='type="checkbox" name="train"  value="'+json[i].wpId+'"></td>';
                    if( json[i].wpName == null){
                        str+='<td></td>'
                    }else{
                        str+='<td>'+json[i].wpName+'</td>'
                    }
                    if(json[i].wpId == null){
                        str+='<td></td>'
                    }else{
                        str+='<td>'+json[i].wpId+'</td>'
                    }
                    if(json[i].wpType != null){
                        str+='<td>'+json[i].wpType+'</td>'
                    }else{
                        str+='<td></td>'
                    }
                    if(json[i].wpGgid != null){
                        str+='<td>'+json[i].wpGgid+'</td>'
                    }else{
                        str+='<td></td>'
                    }
                    if(json[i].wpPrice != null){
                        str+='<td>'+json[i].wpPrice+'</td>'
                    }else{
                        str+='<td></td>'
                    }
                    if(json[i].wpCreator != null){
                        str+='<td>'+json[i].wpCreator+'</td>'
                    }else{
                        str+='<td></td>'
                    }
                    if(json[i].wpCreationtime != null){
                        str+='<td>'+json[i].wpCreationtime+'</td>'
                    }else{
                        str+='<td></td>'
                    }
                    if(json[i].wpLastmodifier != null){
                        str+='<td>'+json[i].wpLastmodifier+'</td>'
                    }else{
                        str+='<td></td>'
                    }
                    if(json[i].wpLastmodificationtime != null){
                        str+='<td>'+json[i].wpLastmodificationtime+'</td>'
                    }else{
                        str+='<td></td>'
                    }
                    if(json[i].wpSchoolid != null){
                        str+='<td>'+json[i].wpSchoolid+'</td>'
                    }else{
                        str+='<td></td>'
                    }

                    str+='</tr>';
                }
                $(".head1 tr:not(':first')").remove();
                $('.head1').append(str)
            },
            error: function(){alert('Error');}
        });

    });

    //单击选中
    $(".xysj td").live('click',function(){
        $('input:checkbox[name=train]:checked').each(function(i) {
            $(this).removeAttr("checked");

        });
        $(this).parent().find("input:checkbox").attr('checked','checked');
    });

    //由于和input:checkbox冲突，在选择一次
    $("#table1 tr td input:checkbox").live('click',function(){
        if($(this).is(':checked')){
            $(this).removeAttr("checked");
        }else{
            $(this).attr("checked",":checked")
        }
    });
    //单击选中
    $("#table1 tr td").live('click',function(){
        if($(this).parent().find("input:checkbox").is(':checked')){
            $(this).parent().find("input:checkbox").removeAttr("checked");
        }else{
            $(this).parent().find("input:checkbox").attr("checked",":checked")
        }
    });

    //    选择数据
    $('.subtn1').click(function () {
        var fseq = $(".stu").val();
        var wpid = "";//fid
        var rkGoodsname = "";//物品名称
        var rkGoodstype = "";//物品状态
        var rkGgid="";//规格
        var rkGoodsprice="";//物品单价
        $('input:checkbox[name=train]:checked').each(function (i) {
            if (0 == i) {
                wpid = $(this).val();
                rkGoodsname = $(this).parent().next().text();
                rkGoodstype = $(this).parent().next().next().next().text();
                rkGgid=$(this).parent().next().next().next().next().text();
                rkGoodsprice=$(this).parent().next().next().next().next().next().text();
            }
        });
        if(wpid == ""){
            alert("请至少选择一条数据");
            return false
        }
        wpDate(fseq,wpid,rkGoodsname,rkGoodstype,rkGgid,rkGoodsprice);
    });

    //双击确定
    $(document).on('dblclick','.xysj td',function(){
        var fseq = $(".stu").val();
        var wpid = "";//wupin的fid
        var rkGoodsname = "";//车辆
        var rkGoodstype = "";//物品状态
        var rkGgid="";//规格
        var rkGoodsprice="";//物品单价
        $('input:checkbox[name=train]:checked').each(function (i) {
            if (0 == i) {
                wpid = $(this).val();
                rkGoodsname = $(this).parent().next().text();
                rkGoodstype = $(this).parent().next().next().next().text();
                rkGgid=$(this).parent().next().next().next().next().text();
                rkGoodsprice=$(this).parent().next().next().next().next().next().text();
            }
        });
        wpDate(fseq,wpid,rkGoodsname,rkGoodstype,rkGgid,rkGoodsprice);
    });
    //放入物品数据
    function wpDate(fseq,wpid,wpName,wpType,wpGgid,wpPrice){
        $('.'+fseq+'').find(".rkGoodsname").val(wpName);
        $('.'+fseq+'').find(".rkGoodstype").val(wpType);
        $('.'+fseq+'').find(".rkGgid").val(wpGgid);
        $('.'+fseq+'').find(".rkGgid").next().val(wpid)
        $('.'+fseq+'').find(".rkGoodsprice").val(wpPrice);
        $('#modal-overlay').css('visibility','hidden');
        $('.modal-data1').css('visibility','hidden');
    }
    //num是要处理的数字  v为要保留的小数位数
    function decimal(num,v){
        var vv = Math.pow(10,v);
        return Math.round(num*vv)/vv;
    }

    //审核,反审核弹框
    $("#sh,#fsh").click(function () {
        var type = $(this).next().val();
        $("#type").val(type);
        if (type == 1) {
            $('#modal-overlay').css('visibility', 'visible');
            $('.modal-data9').css('visibility', 'visible');
            $('li input:radio:first').attr('checked', 'checked');
        }
        else if (type == 2) {
            $('#modal-overlay').css('visibility', 'visible');
            $('.modal-data10').css('visibility', 'visible')
        }
    });

    //审核,反审核
    $("#auditsubmit,#againstAuditsubmit").click(function () {
        //防止重复提交
        $(this).attr("disabled", "disabled");
        var state = $('li input[type="radio"]:checked ').val();//同意/不同意
        var fid = $("#fid").val();//fid
        var fnumber = $("input[name='fnumber']").val();//编码
        var type = $("#type").val();
        var message;
        if (type == '1') {
            message = $("#auditcomment").val();
        } else {
            message = $("#againstAuditcomment").val();
        }
        $.ajax({
            url: '<%=path%>/DrivingSys/auditInwarehouse',
            type: "post",
            data: {'fid': fid, 'type': type, 'fnumber': fnumber, 'message': message, 'state': state},
            dataType: "json",
            success: function (json) {
                var url = '/queryswareHouse/look.action';
                if (type == '1') {
                    if (json == '1') {
                        showAlert('审核成功,并且此流程已结束', url)
                    } else if (json == '2') {
                        showAlert('审核成功', url)
                    } else {
                        showAlert('审核失败', url)
                    }
                } else {
                    if (json == '1') {
                        showAlert('反审核成功', url)
                    } else if (json == '2') {
                        showAlert('没有找到任务', url)
                    } else if (json == '0') {
                        showAlert('找不到流程节点', url)
                    }
                }
            },
            error: function () {
                $("#againstAuditsubmit,#auditsubmit").attr("disabled", false);//去除input元素的disabled属性
                alert('错误');
            }
        })
    });

    //提交
    $("#submit").click(function () {
        $.messager.confirm('提示', '是否提交,提交后不会改变修改后的值', function (r) {
            if (r) {
                var url = '/queryswareHouse/look.action';
                var fid = $("#fid").val();
                var fnumber = $("input[name='fnumber']").val();
                var auditState = $("#auditState").val();
                $.ajax({
                    url: '<%=path%>/DrivingSys/submitInwareHouse',
                    type: "post",
                    data: {'fid': fid, 'fnumber': fnumber, 'auditState': auditState},
                    dataType: "json",
                    success: function (json) {
                        if (json == 1) {
                            showAlert('提交成功', url)
                        } else {
                            showAlert('提交失败', url)
                        }
                    },
                    error: function () {
                        alert('错误');
                    }
                })
            }
        })
    })
    //验证单据下是否有数据
    function verify() {
        var s = 0;
        $("input[name='rkGoodsname']").each(function () {
            if ($(this).val() == '' || $(this).val() == null) {
               s=0;
            } else {


                $("input[name='rkInwarehouseprice']").each(function () {
                    if ($(this).val() == '' || $(this).val() == null) {

                    } else {
                        s=2;
                        return false;
                    }

                });

                $("input[name='rkInwarehousequantity']").each(function () {
                    if ($(this).val() == '' || $(this).val() == null) {

                    } else {

                        s=3;
                        return false;
                    }

                });
                s = 1;
                return false;
            }

        })



        var ywrq = $("#ywrq").val();
        if (ywrq == null || ywrq == '') {
            alert("业务日期不能为空");
            return false;
        }

        if (s == 0) {
            alert("物品名不能为空");
            return false;
        }

        if(s==2){
            alert("物品单价不能为空");
            return false;

        }
        if(s==3){
            alert("物品数量不能为空");
            return false;

        }

        $("input[type='submit']").attr("disabled", "disabled");
    }
</script>
</html>